package com.icode.core.model.order;

import com.icode.core.model.AbstractEntity;
import com.icode.core.model.house.HouseInfo;
import com.icode.core.model.house.HouseWeek;
import com.icode.core.model.user.Address;
import com.icode.core.model.user.UserInfo;

import javax.persistence.*;

/**
 * Created with IntelliJ IDEA.
 * User: xianfei
 * Date: 15-1-20
 * Time: 上午10:06
 * To change this template use File | Settings | File Templates.
 */
@Entity
@Table(name = "orders")
public class Order extends AbstractEntity {

    @Embedded
    private OrderInfo orderInfo;

    @OneToOne
    @JoinColumn(name = "house_week_id")
    private HouseWeek houseWeek;

    @ManyToOne(cascade = {CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REFRESH})
    @JoinColumn(name = "user_info_id")
    private UserInfo userInfo;

    @ManyToOne
    @JoinColumn(name = "house_info_id")
    private HouseInfo houseInfo;

    @ManyToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "address_id")
    private Address address;

    public Order() {
    }


    public Order(HouseWeek houseWeek, HouseInfo houseInfo, OrderInfo orderInfo, UserInfo userInfo) {
        this.houseWeek = houseWeek;
        this.houseInfo = houseInfo;
        this.orderInfo = orderInfo;
        this.userInfo = userInfo;
    }

    public OrderInfo orderInfo() {
        return orderInfo;
    }

    public UserInfo userInfo() {
        return userInfo;
    }

    public HouseInfo houseInfo() {
        return houseInfo;
    }

    public HouseWeek houseWeek() {
        return houseWeek;
    }

    public Address address() {
        return address;
    }
}
